package com.itheima.service;

import com.itheima.dao.TeacherDao;
import com.itheima.domain.Teacher;

import java.awt.desktop.PreferencesEvent;
import java.util.ArrayList;

/*
老师 业务处理类
成员变量   dao
构造方法  默认的无参构造
成员方法  增删改查
        判断学号是否存在


 */
public class TeacherService {
    private TeacherDao dao = new TeacherDao();

    //增  参数 Teacher  teacher  返回值类型 void
    public void addTeacher(Teacher teacher) {
        dao.addTeacher(teacher);
    }

    //删  参数  String  sid  返回值类型 void
    public void deleteTeacher(String sid) {
        dao.deleteTeacher(sid);
    }

    //改  参数 String sid Teacher teacher  返回值类型  void
    public void updateTeacher(String sid, Teacher teacher) {
        dao.updateTeacher(sid, teacher);
    }

    //查所有  参数 没有 返回值类型 ArrayList<Teacher>
    public ArrayList<Teacher> findAllTeachers() {
        return dao.findAllTeachers();
    }

    //判断  参数 String sid 返回值类型 boolean
    public boolean isExists(String sid) {
        ArrayList<Teacher> list = dao.findAllTeachers();
        for (int i = 0; i < list.size(); i++) {
            Teacher teacher = list.get(i);
            if(teacher!=null&&sid.equals(teacher.getSid())){
                return true;
            }
        }
        return false;
    }


}
